package com.ruoyi.aftserv.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.oa.domain.ManageGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.aftserv.mapper.ManageGradeClassMapper;
import com.ruoyi.aftserv.domain.ManageGradeClass;
import com.ruoyi.aftserv.service.IManageGradeClassService;
import com.ruoyi.common.core.text.Convert;

/**
 * 班级Service业务层处理
 * 
 * @author 张艳羽
 * @date 2024-08-19
 */
@Service
public class ManageGradeClassServiceImpl implements IManageGradeClassService 
{
    @Autowired
    private ManageGradeClassMapper manageGradeClassMapper;

    /**
     * 查询班级
     * 
     * @param id 班级主键
     * @return 班级
     */
    @Override
    public ManageGradeClass selectManageGradeClassById(Long id)
    {
        return manageGradeClassMapper.selectManageGradeClassById(id);
    }

    /**
     * 查询班级列表
     * 
     * @param manageGradeClass 班级
     * @return 班级
     */
    @Override
    public List<ManageGradeClass> selectManageGradeClassList(ManageGradeClass manageGradeClass)
    {
        return manageGradeClassMapper.selectManageGradeClassList(manageGradeClass);
    }

    /**
     * 新增班级
     * 
     * @param manageGradeClass 班级
     * @return 结果
     */
    @Override
    public int insertManageGradeClass(ManageGradeClass manageGradeClass)
    {
        manageGradeClass.setCreateTime(DateUtils.getNowDate());
        return manageGradeClassMapper.insertManageGradeClass(manageGradeClass);
    }

    /**
     * 修改班级
     * 
     * @param manageGradeClass 班级
     * @return 结果
     */
    @Override
    public int updateManageGradeClass(ManageGradeClass manageGradeClass)
    {
        manageGradeClass.setUpdateTime(DateUtils.getNowDate());
        return manageGradeClassMapper.updateManageGradeClass(manageGradeClass);
    }

    /**
     * 批量删除班级
     * 
     * @param ids 需要删除的班级主键
     * @return 结果
     */
    @Override
    public int deleteManageGradeClassByIds(String ids)
    {
        return manageGradeClassMapper.deleteManageGradeClassByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除班级信息
     * 
     * @param id 班级主键
     * @return 结果
     */
    @Override
    public int deleteManageGradeClassById(Long id)
    {
        return manageGradeClassMapper.deleteManageGradeClassById(id);
    }

    @Override
    public boolean checkClassCodeUnique(ManageGradeClass gradeClass) {
        Long classId = StringUtils.isNull(gradeClass.getId()) ? -1L : gradeClass.getId();
        ManageGradeClass info = this.manageGradeClassMapper.checkClassCodeUnique(gradeClass.getClassCode());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != classId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
